package com.ktjiaoyu.server.controller;

import com.ktjiaoyu.server.domain.dto.LoginDto;
import com.ktjiaoyu.server.domain.pojo.Admin;
import com.ktjiaoyu.server.service.AdminService;
import com.ktjiaoyu.server.utils.JwtTokenUtil;
import com.ktjiaoyu.server.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@Api(tags = "认证相关接口")
public class LoginController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/doLogin")
    @ApiOperation(value = "登录接口")
    public ResponseResult doLogin(@RequestBody LoginDto loginDto ){
        // 检查验证码
        if(!adminService.checkCaptcha(loginDto.getUuid(),loginDto.getCaptcha())){
            return ResponseResult.error("验证码错误");
        }
        String token = adminService.login(loginDto);

        ResponseResult responseResult = ResponseResult.success("登录成功");
        responseResult.put("token", token);


        return responseResult;
    }

//    @PostMapping("/doLogout")
//    public ResponseResult doLogout(){
//
//        sysUserService.logout();
//
//        ResponseResult responseResult = new ResponseResult<Map>(HttpStatus.OK.value(),"登出成功");
//
//        return responseResult;
//    }
}